home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Video Toaster 4.0
/
Video Toaster v4.0.iso
/
arexx
/
modeler
/
trajmotion.lwm
< prev
next >
Wrap
Text File
|
1993-12-13
|
4KB
|
165 lines
/* CMD: Trajectory Motion
* Make Ballistic Trajectory Motion Path for LW
* By Arnie Cachelin © 1992 NewTek Inc.
*/
NUMERIC DIGITS 6
call addlib "LWModelerARexx.port", 0
signal on error
signal on syntax
call addlib "rexxsupport.library", 0, -30, 0
MATHLIB="rexxmathlib.library"
IF POS(MATHLIB , SHOW('L')) = 0 THEN
IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
call notify(1,"!Can't find "MATHLIB)
exit
END
sysnam = 'Ballistic Trajectory Maker '
version = 'v1.0'
Frames=30
h=0; p=0; b=0
xsc=1; ysc=1; zsc=1
File.type="LWMO"
SecsPerFrame=1/30
Time=SecsPerFrame*Frames
SlicesPerFrame=10
dt=SecsPerFrame/SlicesPerFrame
g=9.8 /* acceleration of gravity in m/s */
call req_begin sysnam
id_mes = req_addcontrol("Make a projectile", 'T', "motion for LW, using real physics!")
id_frames = req_addcontrol("Frames", 'n')
id_keysp = req_addcontrol("Key Spacing", 'n')
id_x0 = req_addcontrol("Initial Position", 'v',0)
id_y0 = req_addcontrol("Ground Level Y = ", 'n',0)
id_elev = req_addcontrol("Launch Elevation (°)", 'n')
id_dir = req_addcontrol("Launch Direction (°)", 'n')
id_dE = req_addcontrol("Bounciness", 'n',0) /* used to be called Elasticity, but that was too technical :-O */
id_T = req_addcontrol("Hang Time (s)", 'n',0)
call req_setval id_frames, Frames
call req_setval id_T, Time
call req_setval id_Keysp, 5
call req_setval id_x0,0,0
call req_setval id_dE,.75,.75
call req_setval id_y0,0,0
call req_setval id_elev,75
call req_setval id_dir,0
if (~req_post()) then do
call req_end
exit
end
frames = req_getval(id_frames) % 1
KeySpacing = req_getval(id_keysp)
theta = req_getval(id_dir)
phi = req_getval(id_elev)
parse value req_getval(id_x0) with xi yi zi .
y0= req_getval(id_y0)
dE= req_getval(id_dE)
HTime = req_getval(id_dE)
call req_end
ENVFile=getfilename("-- Save Motion --","motions")
if ENVFile ~="(none)" then File.Name=ENVFile
else exit
/* WARNING: physics part approaching */
Time=SecsPerFrame*Frames
Keys=1+Frames%KeySpacing
frame=0
slice=0
/* For ballistic trajectory, Vx=V*cos(a), Vy=V*sin(a), Y=((Vy)^2)/g, T=2*Vy/g
==> X=T*Vx=2*Vy*Vx/g. Setting shot duration will be the priority, so the
only input will be the time. The height, Y, will then be set since:
Y=((T*g/2)^2)/g =(g*T^2)/4. Vx is arbitrary, but it determines the angle
and the distance. To make X=Y, use Vx=Vy/4, which is about 76 degrees.
I'll add wind a bit later!!!
*/
/* Initial Conditions */
vyi=HTime*g/2
vxi=vyi*tan(phi)
vxi=vxi*cos(theta)
vzi=vxi*sin(theta)
x=xi; y=yi; z=zi
vx=vxi; vy=vyi; vz=vzi
call meter_begin Frames*SlicesPerFrame+3, 'Generating Motion'
call WriteHeader(mot,keys)
do t=0 to Time+dt by dt
if slice//SlicesPerFrame = 0 then do
if frame//KeySpacing=0 then
call WriteKey(mot,frame,0)
else if frame=Frames then
call WriteKey(mot,frame,0)
frame=frame+1
end
slice=slice+1
vx=vx+dt*ax(x,y,z)
vy=vy+dt*ay(x,y,z)
vz=vz+dt*az(x,y,z)
x=x + dt*vx
z=z + dt*vz
y=y + dt*vy
if y<=y0 then do /* Bounce! */
y=y - dt*vy /* Jump up to prev y */
vy=-dE*vy /* reverse velocity, scale down by elasticity factor */
end
call meter_step
end
call close mot
call meter_end
call notify(1,'!Created LightWave Motion File: 'File.name)
exit
ax: procedure
arg x,y,z
return(0)
ay: procedure expose g
arg x,y,z
return(-g)
az: procedure
arg x,y,z
return(0)
WriteKey: PROCEDURE EXPOSE x y z h p b xsc ysc zsc
arg MotFile, frame, lin
channels=x y z h p b xsc ysc zsc
spline=frame lin "0.0 0.0 0.0"
say channels spline
call writeln(MotFile,channels)
call writeln(MotFile,spline)
return frame
WriteHeader: PROCEDURE EXPOSE File.
arg MotFile, Keys
if open(MotFile,File.name,'W') then do
call writeln(MotFile,File.type)
call writeln(MotFile,"1") /* magic # */
call writeln(MotFile,"9") /* Channels */
call writeln(MotFile,Keys)
end
else do
Bummer("Can't open Motion file : "File.name)
end
return 1
Bummer:
ARG etxt
t=Notify(1,'!Rexx Script Error','@'ETxt)
exit
syntax:
error:
call end_all
t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
exit